package com.xhwl.centiotdata.config.vehicle;


import com.xhwl.centiotdata.pojo.enums.vehicle.VehicleHandlerEnum;
import com.xhwl.centiotdata.service.cent.IDeviceProductService;
import com.xhwl.centiotdata.utils.EnumDynamicUtil;
import com.xhwl.common.pojo.cent.device.DeviceProduct;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 初始化后，动态生成枚举类中的枚举值
 */
@Slf4j
@Component
public class InitEnumRunner implements CommandLineRunner {

    @Autowired
    private IDeviceProductService iDeviceService;

    @Override
    public void run(String... args) throws Exception {
        List<DeviceProduct> deviceProductList = iDeviceService.list();
//        将ICC智能物联管理平台演示的productId与对应的实现类进行绑定
        DeviceProduct deviceProduct = deviceProductList.stream().filter(s -> {
            if (s.getName().contains("大华ICC平台")) {
                return true;
            } else {
                return false;
            }
        }).findAny().orElse(null);
        if(deviceProduct!=null){
            EnumDynamicUtil.addEnum(VehicleHandlerEnum.class,
                    "VEHICLE_DAHUA_ICC",
                    new Class<?>[]{Integer.class,String.class},
                    new Object[]{deviceProduct.getId(),"daHuaIccIntegrationHandler"});
        }

        //富士车行系统
        DeviceProduct fuSHiDeviceProduct = deviceProductList.stream().filter(s -> {
            if (s.getName().contains("富士车行系统")) {
                return true;
            } else {
                return false;
            }
        }).findAny().orElse(null);
        if(fuSHiDeviceProduct!=null){
            EnumDynamicUtil.addEnum(VehicleHandlerEnum.class,
                    "VEHICLE_FUSHI",
                    new Class<?>[]{Integer.class,String.class},
                    new Object[]{fuSHiDeviceProduct.getId(),"fuShiIntegrationHandler"});
        }
    }


}